import { Request } from '@/utils'

export function getGatewayList(callback) {
    var request = new Request()
    request.get('deviceManager/getGatewayList', res => {
        if(res.success && res.data) {
            if(callback) {
                var list = []
                var gatewayCodeToInfo = {}
                if(res.data) {
                    res.data.forEach(v => {
                        gatewayCodeToInfo[v.code] = {host : v.ip, port : v.gatewayHttpPort}
                        v.value = v.code
                        v.name = v.name
                        list.push(v)
                    })
                }
                callback(list, gatewayCodeToInfo)
            }
        }
    })
}

export function getAgentList(callback) {
    var request = new Request()
    request.get('deviceManager/getAgentNames', res => {
        if(res.success && res.data) {
            if(callback) {
                callback(res.data)
            }
        }
    })
}

export function getStoreList(callback, agentId = '') {
    var request = new Request()
    request.get('deviceManager/getStoreNames', res => {
        if(res.success && res.data) {
            if(callback) {
                callback(res.data)
            }
        }
    }, {agentId})
}

export function getVersionList(callback) {
    var request = new Request()
    request.get('upgrade/getVersionSelect', res => {
        if(res.success && res.data) {
            if(callback) {
                var list = []
                if(res.data) {
                    res.data.forEach(v => {
                        v.value = v.id
                        v.name = v.name
                        list.push(v)
                    })
                }
                callback(res.data)
            }
        }
    })
}

